package com.css.crm.vo;

import java.io.Serializable;

/**
 * Abstract class for all object permissions
 */
/*
 * Log			Date			Name					Description
 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
 */
public class AbstractObjectPermission implements AccessControllable, Serializable {
	
	private static final long serialVersionUID = 1L;
	private String objectId;
	private String type;
	private String description;
	private String parentObjectId;
	private String permission;
	private String uri;

	public String getObjectId() {
		return objectId;
	}

	public void setObjectId(String objectId) {
		this.objectId = objectId;
		if (this.objectId != null) {
			this.objectId = this.objectId.toUpperCase();
		}
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getParentObjectId() {
		return parentObjectId;
	}

	public void setParentObjectId(String parentObjectId) {
		this.parentObjectId = parentObjectId;
		if (this.parentObjectId != null) {
			this.parentObjectId = this.parentObjectId.toUpperCase();
		}
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	/**
	 * Return details of object permission as a string
	 * @return String that represents details of object permission
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public String toString() {
		return getObjectId() + " " + getType() + " " + getPermission() + " " + getParentObjectId();
	}

	/**
	 * Check if the object is readable
	 * @return true if the object is readable
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public boolean isReadable() {
		if (permission != null) {
			return permission.indexOf("R") != -1;
		}
		return false;
	}

	/**
	 * Check if the object is writable
	 * @return true if the object is writable
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public boolean isWritable() {
		if (permission != null) {
			return permission.indexOf("W") != -1;
		}
		return false;
	}

	/**
	 * Check if the object is executable
	 * @return true if the object is executable
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public boolean isExecutable() {
		if (permission != null) {
			return permission.indexOf("E") != -1;
		}
		return false;
	}
	
	/**
	 * Check if the object is updatable
	 * @return true if the object is updatable
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public boolean isUpdatable() {
		if (permission != null) {
			return permission.indexOf("U") != -1;
		}
		return false;
	}
	
	/**
	 * Check if the object is insertable
	 * @return true if the object is insertable
	 */
	/*
	 * Log			Date			Name					Description
	 * 0024746	 	2012 DEC 18		lawrence.ng.c.k			Creation
	 */
	public boolean isInsertable() {
		if (permission != null) {
			return permission.indexOf("I") != -1;
		}
		return false;
	}

}
